package com.paomi.client.activity.detail;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.widget.NestedScrollView;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.paomi.client.GlideApp;
import com.paomi.client.R;
import com.paomi.client.activity.detail.adapter.CommentListAdapter;
import com.paomi.client.activity.detail.adapter.RVItemDecoration;
import com.paomi.client.activity.detail.adapter.ReplyItemAdapter;
import com.paomi.client.activity.detail.model.Comment;
import com.paomi.client.activity.detail.model.DetailTicketBean;
import com.paomi.client.activity.detail.model.PlanBean;
import com.paomi.client.activity.detail.presenter.DetailTicketPresenter;
import com.paomi.client.activity.login.LoginActivity;
import com.paomi.client.activity.reply.ReplyActivity;
import com.paomi.client.activity.shopCar.ShopsCarActivity;
import com.paomi.client.base.BaseLCEActivity;
import com.paomi.client.bean.BaseJSON;
import com.paomi.client.bean.UserUtils;
import com.paomi.client.fragment.first.model.TicketJson;
import com.paomi.client.net.Constants;
import com.paomi.client.utils.BlurTransformation;
import com.paomi.client.utils.Datas;
import com.paomi.client.utils.ToastUtil;
import com.paomi.client.utils.UIUtils;
import com.paomi.client.utils.Util;
import com.paomi.client.view.ExpandLayout;
import com.paomi.client.widget.StarBar;
import com.paomi.client.widget.header.HeaderGetView;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;

public class DetailTicketActivity extends BaseLCEActivity<Comment, DetailTicketPresenter> {


    @BindView(R.id.img_bg)
    ImageView img_bg;
    @BindView(R.id.get_bg)
    RelativeLayout get_bg;
    @BindView(R.id.ticket_iv)
    RoundedImageView ticketIv;
    @BindView(R.id.ticket_title)
    TextView ticketTitle;
    @BindView(R.id.time_iv)
    TextView timeIv;
    @BindView(R.id.before_show)
    TextView before_show;
    @BindView(R.id.price_before)
    TextView price_before;
    @BindView(R.id.time_tv)
    TextView timeTv;
    @BindView(R.id.ll_time)
    LinearLayout llTime;
    @BindView(R.id.location_iv)
    TextView locationIv;
    @BindView(R.id.location_tv)
    TextView locationTv;
    @BindView(R.id.ll_location)
    LinearLayout llLocation;
    @BindView(R.id.money_tv)
    TextView moneyTv;
    @BindView(R.id.money_txt)
    TextView money_txt;

    @BindView(R.id.score_tv)
    TextView scoreTv;
    @BindView(R.id.rat_bar)
    StarBar ratBar;
    @BindView(R.id.next_bar)
    TextView nextBar;
    @BindView(R.id.rb_show_txt)
    RadioButton rbShowTxt;
    @BindView(R.id.rb_show_ask)
    RadioButton rbShowAsk;
    @BindView(R.id.web_deta)
    WebView webDetail;//演出简介
    @BindView(R.id.web_intro)
    WebView web_intro;//购票须知
    @BindView(R.id.recycler_list)
    RecyclerView recyclerList;
    @BindView(R.id.nes_scroll)
    NestedScrollView nesScroll;
    @BindView(R.id.ticket_favor)
    TextView ticketFavor;
    @BindView(R.id.ticket_msg)
    TextView ticketMsg;
    @BindView(R.id.msg_num)
    TextView msgNum;
    @BindView(R.id.tv_login)
    Button tvLogin;
    @BindView(R.id.button_goback)
    TextView buttonGoback;
    @BindView(R.id.null_num)
    TextView nullNum;
    @BindView(R.id.ll_expand)
    LinearLayout llExpand;
    @BindView(R.id.comment_title)
    TextView commentTitle;
    @BindView(R.id.null_tv)
    TextView nullTv;
    @BindView(R.id.expandLayout)
    ExpandLayout expandLayout;
    @BindView(R.id.change_tv)
    TextView changeTv;
    @BindView(R.id.ticket_shops)
    TextView ticketShops;
    @BindView(R.id.card_num)
    TextView cardNum;
    @BindView(R.id.shops_rl)
    RelativeLayout shopsRl;
    @BindView(R.id.btn_shops)
    Button btnShops;
    @BindView(R.id.ptr_main)
    PtrClassicFrameLayout ptrMain;
    @BindView(R.id.coupon_txt)
    TextView couponTxt;
    @BindView(R.id.coupon_get)
    TextView couponGet;
    @BindView(R.id.coupon_txt_get)
    TextView couponTxtGet;
    @BindView(R.id.next_coupon)
    TextView nextCoupon;
    @BindView(R.id.layout_get_coupon)
    LinearLayout layoutGetCoupon;
    @BindView(R.id.layout_coupon)
    LinearLayout layoutCoupon;
    @BindView(R.id.acc_txt)
    TextView accTxt;
    @BindView(R.id.acc_content)
    TextView accContent;
    @BindView(R.id.acc_get)
    TextView accGet;
    @BindView(R.id.layout_acc)
    LinearLayout layoutAcc;

    private Mobile mobile = new Mobile();
    private JavaMobile javaMobile = new JavaMobile();
    private float measuredHeight = 0;//获取webview内容加载的高度
    private float measuredInroHeight = 0;//获取webview内容加载的高度
    private boolean changHeight = false;//演出简介展开，收缩的点击
    private boolean changIntro = false;//购票须知展开，收缩的点击
    private CommentListAdapter listAdapter;
    private String getId;
    private DetailTicketBean.TicketBean ticketBean = null;
    private TicketJson ticketJson = null;//演出信息数据
    private int pageNum = 1;
    private boolean isFavor = true;
    private boolean isLike = true;
    //    private TextView isItemLike;
    private List<Comment> commentList = new ArrayList<>();//记录上拉加载的条数
    private boolean isCanTicket = false;

    @NonNull
    @Override
    public DetailTicketPresenter createPresenter() {
        return new DetailTicketPresenter();
    }

    @Override
    protected String setTitle() {
        return "详情";
    }

    @Override
    protected void showBack(TextView button_goback) {
        button_goback.setVisibility(View.VISIBLE);
        button_goback.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        button_goback.setTextColor(getResources().getColor(R.color.main_color));
        button_goback.setText(getResources().getString(R.string.back_normal) + "返回");
        button_goback.setTypeface(iconfont);
    }

    @NonNull
    @Override
    protected int getLayoutId() {
        return R.layout.activity_detail_ticket;
    }

    @NonNull
    @Override
    protected RecyclerView createRecycler() {
        return recyclerList;
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        timeIv.setTypeface(iconfont);
        locationIv.setTypeface(iconfont);
        nextBar.setTypeface(iconfont);
        ticketFavor.setTypeface(iconfont);
        ticketMsg.setTypeface(iconfont);
        ticketShops.setTypeface(iconfont);
        nextCoupon.setTypeface(iconfont);
        getId = getIntent().getStringExtra("getId");
        // 使WebView不可滚动
        webDetail.setOnTouchListener((v, event) -> (event.getAction() == MotionEvent.ACTION_MOVE));
        webDetail.getSettings().setJavaScriptEnabled(true);
        webDetail.addJavascriptInterface(mobile, "mobile");
        webDetail.setWebChromeClient(new WebChromeClient());
        web_intro.setOnTouchListener((v, event) -> (event.getAction() == MotionEvent.ACTION_MOVE));
        web_intro.getSettings().setJavaScriptEnabled(true);
        web_intro.setWebChromeClient(new WebChromeClient());
        expandLayout.setRetractHeight(300f);
        expandLayout.initExpand(false);
//        expandLayout.setRetractHeight(300f);//可通过这段设置缩放高度
//        expandLayout.initExpand(true);
        recyclerList.setLayoutManager(UIUtils.getRecyclerViewManager(false, this));
        // 设置为 true
        recyclerList.setHasFixedSize(true);
        recyclerList.setItemAnimator(new DefaultItemAnimator());
        // 设置为 false
        recyclerList.setNestedScrollingEnabled(false);// 解决滑动冲突
        setPtrFrameLayout(ptrMain);
        setPullToRefreshEnable(false);
//        listAdapter=new CommentListAdapter(this);
//        recyclerList.setAdapter(listAdapter);
//        listAdapter.setData(comments);
        getPresenter().setDetailData(getId);
        getPresenter().setLoadData(this, 1);
        HeaderGetView header = new HeaderGetView(this);
        ptrMain.setHeaderView(header);
        ptrMain.addPtrUIHandler(header);
        ptrMain.setPtrHandler(new PtrHandler() {
            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout ptrFrameLayout, View view, View view2) {
                return nesScroll.getScrollY() == 0;
            }

            @Override
            public void onRefreshBegin(PtrFrameLayout ptrFrameLayout) {
                getPresenter().setDetailData(getId);
                pageNum = 1;
                getPresenter().setLoadData(DetailTicketActivity.this, pageNum);
            }
        });
        //解决NestedScrollView嵌套RecyclerView滑动冲突导致无法正常调用加载更多功能
        nesScroll.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                //判断是否滑到的底部
                if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight())) {
                    //调用刷新控件对应的加载更多方法
                    // 最后一项完全显示, 触发操作, 执行加载更多操作 禁用回弹判断
                    if (commentList.size() % Constants.PAGE_SIZE == 0) {
                        getmAdapterWrapper().setLoadItemState(true);
                        onLoad();
                    } else {
                        getmAdapterWrapper().setLoadItemState(false);
                        getmLoadMoreHelper().setLoadMoreFinish();
                    }
                }
            }
        });

    }

//    @Override
//    public void setCommentData(List data) {
//        setData(data,false);
//    }

    @Override
    protected int getItemLayout() {
        return R.layout.item_comment_list;
    }

    @Override
    protected void initEmpty(TextView empty) {

    }

    @Override
    protected void convert(BaseViewHolder helper, Comment item) {
        RoundedImageView user_image = helper.itemView.findViewById(R.id.user_image);
        GlideApp.with(this).load(item.getUserImg()).placeholder(R.mipmap.img_default_head).into(user_image);
        //用户名称
        helper.setText(R.id.comment_user, item.getUserName());
        //用户评论内容
        helper.setText(R.id.comment_content, item.getContent());
        TextView comment_content = helper.itemView.findViewById(R.id.comment_content);
        //子回复列表
        RecyclerView vieList = helper.itemView.findViewById(R.id.reply_list);
        //回复数
        TextView comment_msg_num = helper.itemView.findViewById(R.id.comment_msg_num);
        if (item.getReply() == 0) {//回复列表数0不显示
            comment_msg_num.setText("");
        } else {
            comment_msg_num.setText("" + item.getReply());
        }
        //点赞数
        TextView praise_num = helper.itemView.findViewById(R.id.praise_num);
        praise_num.setText("" + item.getLike());
        LinearLayout ll_height = helper.itemView.findViewById(R.id.ll_height);
        TextView msg_num_iv = helper.itemView.findViewById(R.id.msg_num_iv);
        msg_num_iv.setTypeface(iconfont);
        //是否已点赞
        TextView praise_iv = helper.itemView.findViewById(R.id.praise_iv);
        praise_iv.setTypeface(iconfont);
        if (item.isLike()) {// true 已点赞 false 未点赞
            praise_iv.setText(getResources().getString(R.string.comment_praise));
            praise_iv.setTextColor(getResources().getColor(R.color.main_color));
        } else {
            praise_iv.setText(getResources().getString(R.string.comment_praise_un));
            praise_iv.setTextColor(getResources().getColor(R.color.text_gray_99));
        }
        //时间显示
        TextView comment_time = helper.itemView.findViewById(R.id.comment_time);
        comment_time.setText(Datas.getTimeElapse(item.getTime()));
        TextView next_btn = helper.itemView.findViewById(R.id.next_btn);
        //删除按钮
        TextView my_comment = helper.itemView.findViewById(R.id.my_comment);
        TextView comment_delete = helper.itemView.findViewById(R.id.comment_delete);
        next_btn.setTypeface(iconfont);
        if (item.getReplyComments() != null && item.getReplyComments().getData().size() > 0) {
            vieList.setVisibility(View.VISIBLE);
            vieList.setLayoutManager(Util.getRecyclerViewManager(false, this));
            ReplyItemAdapter replyItemAdapter = new ReplyItemAdapter(this);
            vieList.setAdapter(replyItemAdapter);
            replyItemAdapter.setData(item.getReplyComments().getData());
            //添加左边的时间轴
            vieList.addItemDecoration(new RVItemDecoration(getApplicationContext()));
            //点击子项的内容回复
            replyItemAdapter.OnItemClick(new ReplyItemAdapter.OnItemClick() {
                @Override
                public void setOnContentClick(View view, int pos) {
//                    ReplyContent bean = item.getReplyComments().getData().get(pos);
//                    getPresenter().showCommentDialog(DetailTicketActivity.this, bean, item);
                    Intent intent = new Intent(DetailTicketActivity.this, ReplyActivity.class);
                    intent.putExtra("getId", "" + getId);//商品id
                    intent.putExtra("getComment", (Serializable) ticketBean.getCommentReasons());//举报数据的传递
                    intent.putExtra("pid", "" + item.getId());//被评论的id
                    startActivity(intent);
                }
            });
            if (item.getReplyComments().getData().size() > 1) {
                ll_height.setVisibility(View.VISIBLE);
            } else {
                ll_height.setVisibility(View.GONE);
            }
        }
        //查看更多评论
        ll_height.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(DetailTicketActivity.this, ReplyActivity.class);
                intent.putExtra("getId", "" + getId);//商品id
                intent.putExtra("getComment", (Serializable) ticketBean.getCommentReasons());//举报数据的传递
                intent.putExtra("pid", "" + item.getId());//被评论的id
                startActivity(intent);
            }
        });
        //我的评论和删除按钮的显示
        if (UserUtils.getInstance().getUserInfo1() != null && UserUtils.getInstance().getUserInfo1().getUserId() == item.getUserId()) {
            my_comment.setVisibility(View.VISIBLE);
            comment_delete.setVisibility(View.VISIBLE);
        } else {
            my_comment.setVisibility(View.GONE);
            comment_delete.setVisibility(View.GONE);
        }
        //删除评论
        comment_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getPresenter().deleteComment(DetailTicketActivity.this, "" + item.getId(), helper.getPosition());
            }
        });
        //举报评论
        helper.itemView.findViewById(R.id.comment_tip).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ticketBean != null) {
                    getPresenter().tipComment(DetailTicketActivity.this, iconfont, ticketBean.getCommentReasons(), "" + item.getId());
                }

            }
        });
        //点赞
        praise_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                isItemLike=praise_iv;
                if (getUserInfo() == null) {//未登录的判断
                    getIntent(LoginActivity.class);
                    return;
                }
                if (item.isLike()) {
                    isLike = false;
                } else {
                    isLike = true;
                }
                helper.itemView.setTag(item.getId());
                getPresenter().addLikeClick(isLike, "" + item.getId());
                if (helper.itemView.getTag() != null) {
                    if (isLike && helper.itemView.getTag().equals(item.getId())) {
                        praise_num.setText("" + ((Integer.parseInt(praise_num.getText().toString())) + 1));
                        item.setLike(true);
                        praise_iv.setText(getResources().getString(R.string.comment_praise));
                        praise_iv.setTextColor(getResources().getColor(R.color.main_color));
                    } else {
                        item.setLike(false);
                        praise_num.setText("" + ((Integer.parseInt(praise_num.getText().toString())) - 1));
                        praise_iv.setText(getResources().getString(R.string.comment_praise_un));
                        praise_iv.setTextColor(getResources().getColor(R.color.text_gray_99));
                    }
                }
            }
        });
        //回复
        msg_num_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getPresenter().showCommentDialog(DetailTicketActivity.this, null, item);
            }
        });

    }

    @Override
    protected void onItemClick(View view, Comment item) {

    }

    @OnClick(R.id.btn_shops)
    public void onViewClicked() {
    }

    /**
     * 领取优惠券的点击
     */
    @OnClick(R.id.layout_get_coupon)
    public void onCouponClicked() {
        getPresenter().getCouponList(this,getId,iconfont);
    }

    /**
     * //获取webview加载内容的高度
     */
    private class Mobile {
        @JavascriptInterface
        public void onGetWebContentHeight() {
            //重新调整webview高度
            if (webDetail != null) {
                webDetail.postDelayed(() -> {
                    webDetail.measure(0, 0);
                    measuredHeight = webDetail.getMeasuredHeight();
//                    Log.e("zzz", "measuredHeight=" + measuredHeight);
                    if (measuredHeight > 300) {
                        expandLayout.setRetractHeight(300f);
                        changHeight = true;
                        llExpand.setVisibility(View.VISIBLE);
                        expandLayout.initExpand(false);
                    } else if (measuredHeight == 0) {
                        measuredHeight = webDetail.getContentHeight() * webDetail.getScale();
                        expandLayout.setRetractHeight(measuredHeight);
                        changHeight = false;
                        llExpand.setVisibility(View.GONE);
                        expandLayout.initExpand(false);
                    } else {
                        expandLayout.setRetractHeight(measuredHeight);
                        changHeight = false;
                        llExpand.setVisibility(View.GONE);
                        expandLayout.initExpand(false);
                    }
                }, 100);
            }
        }
    }

    /**
     * //获取webview加载内容的高度
     */
    private class JavaMobile {
        @JavascriptInterface
        public void onGetWebContentHeight() {
            //重新调整webview高度
            if (web_intro != null) {
                web_intro.postDelayed(() -> {
                    web_intro.measure(0, 0);
                    measuredInroHeight = web_intro.getMeasuredHeight();
//                    Log.e("zzz", "measuredHeight=" + measuredHeight);
                    if (measuredInroHeight > 300) {
                        expandLayout.setRetractHeight(300f);
                        changIntro = true;
                        llExpand.setVisibility(View.VISIBLE);
                        expandLayout.initExpand(false);
                    } else if (measuredInroHeight == 0) {
                        measuredInroHeight = web_intro.getContentHeight() * web_intro.getScale();
                        expandLayout.setRetractHeight(measuredInroHeight);
                        changIntro = false;
                        llExpand.setVisibility(View.GONE);
                        expandLayout.initExpand(false);
                    } else {
                        expandLayout.setRetractHeight(measuredInroHeight);
                        changIntro = false;
                        llExpand.setVisibility(View.GONE);
                        expandLayout.initExpand(false);
                    }
                }, 100);
            }
        }
    }

    private int type = 1;//是否在线选座 0 不选座 1选座

    @OnClick({R.id.next_bar, R.id.rb_show_txt, R.id.rb_show_ask, R.id.ll_location, R.id.ll_expand, R.id.ticket_favor
            , R.id.ticket_msg, R.id.tv_login, R.id.btn_shops, R.id.null_tv})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.next_bar://下一个
                break;
            case R.id.rb_show_txt://演出简介
                if (ticketJson != null)
                    changHeight = true;
                web_intro.setVisibility(View.GONE);
                webDetail.setVisibility(View.VISIBLE);
                webDetail.loadData(ticketJson.getIntroduction(), "text/html; charset=UTF-8", null);
                changeTv.setText(getResources().getString(R.string.expaned_get));
                break;
            case R.id.rb_show_ask://购票须知
                if (ticketJson != null)
                    expandLayout.setRetractHeight(300f);
                expandLayout.initExpand(true);
                changIntro = true;
                webDetail.setVisibility(View.GONE);
                web_intro.setVisibility(View.VISIBLE);
                web_intro.loadData(ticketJson.getNotice(), "text/html; charset=UTF-8", null);
                web_intro.setWebViewClient(new WebViewClient() {
                    @Override
                    public void onPageFinished(WebView view, String url) {
                        javaMobile.onGetWebContentHeight();
                    }
                });
                changeTv.setText(getResources().getString(R.string.expaned_get));
                break;
            case R.id.ll_location://查看位置
                break;
            case R.id.ll_expand://展开
                if (web_intro.getVisibility() == View.VISIBLE) {//显示购票须知
                    if (!changIntro) {
                        changeTv.setText(getResources().getString(R.string.expaned_get));
                        changIntro = true;
                        expandLayout.setRetractHeight(300f);
                        expandLayout.initExpand(true);
                    } else {
                        changeTv.setText(getResources().getString(R.string.expaned_false));
                        changIntro = false;
                        expandLayout.setRetractHeight(measuredInroHeight);
                        expandLayout.initExpand(true);
                    }
                } else {
                    if (!changHeight) {
                        changeTv.setText(getResources().getString(R.string.expaned_get));
                        changHeight = true;
                        expandLayout.setRetractHeight(300f);
                        expandLayout.initExpand(true);
                    } else {
                        changeTv.setText(getResources().getString(R.string.expaned_false));
                        changHeight = false;
                        expandLayout.setRetractHeight(measuredHeight);
                        expandLayout.initExpand(true);
                    }
                }

                expandLayout.toggleExpand();
                break;
            case R.id.ticket_favor://收藏
                getPresenter().addCollectionList(isFavor);
                break;
            case R.id.ticket_msg://消息
                getPresenter().showCommentDialog(this, null, null);
                break;
            case R.id.null_tv://消息
                getPresenter().showCommentDialog(this, null, null);
                break;
            case R.id.tv_login://立即购票
                if (ticketJson != null) {
                    type = ticketJson.getGood_type();//是否在线选座 0 不选座 1选座
                    getPresenter().showTicketCalendar(this, iconfont, ticketBean.getPlans(), ticketBean, type, tvLogin);
                }
                break;
            case R.id.btn_shops://加入购物车
                getIntent(ShopsCarActivity.class);
                break;
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
    }

    /**
     * 演出详情接口返回数据
     *
     * @param result
     */
    @Subscribe
    public void onEvent(DetailTicketBean result) {
        if (result.getReturnData() == null) {
            return;
        }
        Util.setWidthAndHeight(img_bg, -1, get_bg.getHeight());
        ticketBean = result.getReturnData();
        ticketJson = result.getReturnData().getGoods();
        timeIv.setVisibility(View.VISIBLE);
        locationIv.setVisibility(View.VISIBLE);
        money_txt.setVisibility(View.VISIBLE);
        GlideApp.with(this).load(ticketJson.getThumb()).placeholder(R.mipmap.img_default_goods).into(ticketIv);
        //设置模糊图片
        GlideApp.with(this).load(ticketJson.getThumb()).placeholder(R.mipmap.img_default_msg).transform(new BlurTransformation(this, 23, 4)).into(img_bg);
        get_bg.setBackgroundColor(getResources().getColor(R.color.color333333));
        get_bg.getBackground().setAlpha(100);
//        GlideApp.with(this).load(ticketJson.getThumb()).placeholder(R.mipmap.img_default_msg).into(new SimpleTarget<Drawable>() {
//            @Override
//            public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
//                img_bg.setImageBitmap(BlurUtils.toBlur(resource,15));
//            }
//        });
        ticketTitle.setText(ticketJson.getName());
        timeTv.setText(ticketJson.getDate());
        if (ticketJson.getSource_price() != null) {
            before_show.setVisibility(View.VISIBLE);
            price_before.setText("" + ticketJson.getSource_price());
            //中间加横线
            price_before.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        }
        locationTv.setText(ticketJson.getVenue_name());
        moneyTv.setText(ticketJson.getPrice());
        if (result.getReturnData().getStar() != null && ("").equals(result.getReturnData().getStar())) {
            nullNum.setVisibility(View.GONE);
            scoreTv.setText(result.getReturnData().getStar());
            float bar = Float.parseFloat(result.getReturnData().getStar());
            ratBar.setStarMark(bar);
        } else {
            nullNum.setVisibility(View.VISIBLE);
        }
        webDetail.loadData(ticketJson.getIntroduction(), "text/html; charset=UTF-8", null);
        if (ticketBean.isCollection()) {//是否收藏该演出 true已收藏 false 未收藏
            isFavor = false;
            ticketFavor.setText(getResources().getString(R.string.favor_imag));
            ticketFavor.setTextColor(getResources().getColor(R.color.main_color));
        } else {
            isFavor = true;
            ticketFavor.setText(getResources().getString(R.string.un_favor_imag));
            ticketFavor.setTextColor(getResources().getColor(R.color.color4A4A4A));
        }
        webDetail.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                mobile.onGetWebContentHeight();
            }
        });
        //判断场次信息里是否有票可选
        for (int i = 0; i < ticketBean.getPlans().size(); i++) {
            PlanBean planBean = ticketBean.getPlans().get(i);
            //演出时间i
            if (planBean.getState().equals("1")) {//判断是否有票 0 无票 1 有票
                Log.e("演出时间", "" + Util.getTime((planBean.getShowDate() * 1000)));
                isCanTicket = true;
                break;
            }
        }
        if (!isCanTicket) {
            tvLogin.setBackgroundColor(getResources().getColor(R.color.text_gray_99));
//            tvLogin.setClickable(false);
        }
        if(ticketJson.isCoupon_flag()){//判断是否可用优惠券
            layoutCoupon.setVisibility(View.VISIBLE);
        }else{
            layoutCoupon.setVisibility(View.GONE);
        }
        if(ticketJson.isIs_integral()) {//判断可用积分
            layoutAcc.setVisibility(View.VISIBLE);
        }else{
            layoutAcc.setVisibility(View.GONE);
        }
    }

    /**
     * 评论列表的数据
     *
     * @param result
     */
    @Subscribe
    public void onEvent(List<Comment> result) {
        commentList.clear();
        commentList.addAll(result);
        if (result.size() > 0) {
            nullTv.setVisibility(View.GONE);
            commentTitle.setVisibility(View.VISIBLE);
        } else {
            nullTv.setVisibility(View.VISIBLE);
            commentTitle.setVisibility(View.GONE);
        }
        setData(result, true);
    }

    /**
     * 评论成功后返回的信息
     *
     * @param result
     */
    @Subscribe
    public void onEvent(BaseJSON result) {
        if (result.returnMessage == null) {
            return;
        }
        if (result.returnMessage.equals("发布成功")) {
            ToastUtil.getToastEmail().ToastShow(this, null, 1, R.layout.toast_view, getResources().getString(R.string.input_sure_msg));
            getPresenter().setLoadData(this, pageNum);
        } else if (result.returnMessage.equals("删除成功")) {
            ToastUtil.getToastEmail().ToastShow(this, null, 1, R.layout.toast_view, getResources().getString(R.string.delete_success));
        } else if (result.returnMessage.equals("举报成功")) {
            ToastUtil.getToastEmail().ToastShow(this, null, 1, R.layout.toast_view, getResources().getString(R.string.tip_success));
        } else if (result.returnMessage.equals("收藏成功")) {
            isFavor = false;
            ticketFavor.setText(getResources().getString(R.string.favor_imag));
            ticketFavor.setTextColor(getResources().getColor(R.color.main_color));
            ToastUtil.getToastEmail().ToastShow(this, null, 1, R.layout.toast_view, getResources().getString(R.string.collect_success));
        } else if (result.returnMessage.equals("取消收藏")) {
            isFavor = true;
            ticketFavor.setText(getResources().getString(R.string.un_favor_imag));
            ticketFavor.setTextColor(getResources().getColor(R.color.color4A4A4A));
            ToastUtil.getToastEmail().ToastShow(this, null, 1, R.layout.toast_view, getResources().getString(R.string.collect_cancel));
        } else if (result.returnMessage.equals("点赞成功")) {
            isLike = false;
            ToastUtil.getToastEmail().ToastShow(this, null, 1, R.layout.toast_view, getResources().getString(R.string.like_success));
        } else if (result.returnMessage.equals("取消点赞")) {
            isLike = true;
            ToastUtil.getToastEmail().ToastShow(this, null, 1, R.layout.toast_view, getResources().getString(R.string.like_cancel));
        }
    }

    @Override
    public void setData(List<Comment> data, boolean pullToRefresh) {
        super.setData(data, pullToRefresh);
        if (commentList.size() % Constants.PAGE_SIZE != 0) {//移除FooterView
            getmAdapterWrapper().setLoadItemVisibility(false);
        } else {
            getmAdapterWrapper().setLoadItemVisibility(true);
        }
        getmLoadMoreHelper().setLoadMoreFinish();
        getmAdapterWrapper().notifyDataSetChanged();
    }

    @Override
    public void onLoad() {
        super.onLoad();
        if (commentList.size() > 0) {
            if (commentList.size() % Constants.PAGE_SIZE == 0) {
                pageNum++;
                getPresenter().setLoadData(this, pageNum);
            } else {
                getmAdapterWrapper().setLoadItemVisibility(false);
                getmLoadMoreHelper().setLoadMoreFinish();
            }
        }

    }
}
